#include "qtimshow.h"
#include "ui_qtimshow.h"
#include <QMouseEvent>
#include <QScrollBar>


QtImShow::QtImShow(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::QtImShow)
{
    ui->setupUi(this);
}

QtImShow::~QtImShow()
{
    delete ui;
}

QLabel *QtImShow::getLabel()
{
    return ui->label;
}

void QtImShow::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
        lastMousePosition = event->globalPos() - frameGeometry().topLeft();
        isDragging = true;
    }
}

void QtImShow::mouseMoveEvent(QMouseEvent *event) {
    if (isDragging && event->buttons() & Qt::LeftButton) {
        QPoint delta = event->globalPos() - lastMousePosition;
        ui->scrollArea->horizontalScrollBar()->setValue(
            ui->scrollArea->horizontalScrollBar()->value() - delta.x());
        ui->scrollArea->verticalScrollBar()->setValue(
            ui->scrollArea->verticalScrollBar()->value() - delta.y());
        lastMousePosition = event->globalPos() - frameGeometry().topLeft();
    }
}

void QtImShow::mouseReleaseEvent(QMouseEvent *event) {
    Q_UNUSED(event);
    isDragging = false;
}
